package com.lwx.test;

import com.lwx.tree.BST;

import java.util.Arrays;

//寻找45的floor和ceil
//rank  45是排名第几
//select  排名是第10的元素是谁
//size  以41为根节点的元素有几个，包括41本身
//depth  深度
//具有重复元素的二分搜索树  1.放在左子树  2.count  重复元素的个数
public class DemoBSTRemove {
    public static void main(String[] args) {
        BST<Integer> tree = new BST<>();
        for (int i = 0; i < 1000; i++) {
            tree.add(i+1);
        }
        tree.remove(10);

        int[] treeArray = new int[tree.getSize()];
        int size = tree.getSize();
        //将树从小到大的元素取出来，放在数组里
        for (int i = 0; i < size; i++) {
            treeArray[i] = tree.removeMin();
        }
        System.out.println(Arrays.toString(treeArray));

        for (int i = 0; i < treeArray.length-1; i++) {
            if(treeArray[i] > treeArray[i+1]){
                throw new IllegalArgumentException("Error");
            }
        }
        System.out.println("Completed!");
    }
}
